package IO流.综合练习.随机点名;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class 第三题 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new FileReader("F\\name.txt"));
        //1.把文件里面的姓名放进集合中
        ArrayList<String> nameList=new ArrayList<>();
        String b;
        while ((b=bf.readLine())!=null){
            nameList.add(b.split("-")[0]);
        }
        //释放资源
        bf.close();
        //2.进行随机点名-->假定第三次必定是"洪华贵"
        //删除集合中的洪华贵
        //创建一个集合储存已经点名了的学生
        ArrayList<String> last=new ArrayList<>();
        nameList.remove("洪华贵");
        int count=1;
        while (count<=10){
            //打乱集合
            Collections.shuffle(nameList);
            //判断count是否等于三
            if (count==3){
                last.add("洪华贵");
                System.out.println("第"+count+"次程序运行:"+"洪华贵");
                count++;
            }
            //判断是否点过名
            if (!last.contains(nameList.get(0))){
                last.add(nameList.get(0));
                System.out.println("第"+count+"次程序运行:"+nameList.get(0));
                count++;
            }
        }
    }
}
